package org.eiahe.hr.performance.controller;

import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.eiahe.hr.performance.domain.PerformancePushRecord;
import org.eiahe.hr.performance.domain.bo.PerformancePushRecordBo;
import org.eiahe.hr.performance.domain.vo.PerformancePushRecordVo;
import org.eiahe.hr.performance.service.IPerformancePushRecordService;
import org.ehe.common.core.domain.R;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckPermission;

import java.util.List;

/**
 * 绩效推送记录Controller
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/performance/pushRecord")
public class PerformancePushRecordController extends BaseController {

    private final IPerformancePushRecordService performancePushRecordService;

    /**
     * 查询绩效推送记录列表
     */
    @SaCheckPermission("performance:pushRecord:list")
    @GetMapping("/list")
    public TableDataInfo<PerformancePushRecordVo> list(PerformancePushRecordBo record, PageQuery pageQuery) {
        return performancePushRecordService.queryPageListVo(record, pageQuery);
    }

    /**
     * 获取绩效推送记录详细信息
     */
    @SaCheckPermission("performance:pushRecord:query")
    @GetMapping(value = "/{recordId}")
    public R<PerformancePushRecordVo> getInfo(@PathVariable("recordId") Long recordId) {
        return R.ok(performancePushRecordService.queryById(recordId));
    }

    /**
     * 新增绩效推送记录
     */
    @SaCheckPermission("performance:pushRecord:add")
    @Log(title = "绩效推送记录", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody PerformancePushRecordBo record) {
        return toAjax(performancePushRecordService.insertByBo(record));
    }

    /**
     * 修改绩效推送记录
     */
    @SaCheckPermission("performance:pushRecord:edit")
    @Log(title = "绩效推送记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody PerformancePushRecordBo record) {
        return toAjax(performancePushRecordService.updateByBo(record));
    }

    /**
     * 删除绩效推送记录
     */
    @SaCheckPermission("performance:pushRecord:remove")
    @Log(title = "绩效推送记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public R<Void> remove(@PathVariable Long[] recordIds) {
        return toAjax(performancePushRecordService.deleteWithValidByIds(List.of(recordIds), true));
    }
}